package leetcode.editor.cn;

import java.util.Arrays;

class SpecialArrayWithXElementsGreaterThanOrEqualX {
    public static void main(String[] args) {
        Solution solution = new SpecialArrayWithXElementsGreaterThanOrEqualX().new Solution();
        solution.specialArray(new int[]{3, 5});
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int specialArray(int[] nums) {
            Integer[] arr = new Integer[nums.length];
            for (int i = 0; i < arr.length; i++) arr[i] = nums[i];
            Arrays.sort(arr, (o1, o2) -> o2 - o1);
            for (int i = 1; i <= nums.length; i++) {
                if (arr[i - 1] >= i && arr[i] < i) return i;
            }

            return -1;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
